package com.jqb.jspcart.service.impl;

import java.sql.SQLException;
import java.util.ArrayList;

import com.jqb.jspcart.bean.Users;
import com.jqb.jspcart.util.SQLHandler;

public class UserServiceImpl {
	
	public boolean isLogin(Users user) throws SQLException   {
		boolean flag = false;
		String sql = "select id from users where name=? and password=?";
		String[] params = {user.getName(),user.getPassword()};
		ArrayList<Object[]> obj = SQLHandler.newInstance().executeQuery(sql, params);
		if(obj.size()!=0){
			flag = true;
		}
		return flag;
	}
	
	public boolean addUser(Users user) throws SQLException {
		boolean flag = false;
		String sql = "insert into users(name,password) values(?,?)";
		String[] params = {user.getName(),user.getPassword()};
		flag = SQLHandler.newInstance().executeUpdate(sql, params);
		return flag;
	}
}